package segmenter;

import vo.StockInfo;

import java.util.ArrayList;
import java.util.List;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.recognition.impl.StopRecognition;
import org.ansj.splitWord.analysis.ToAnalysis;

public class ChineseSegmenterImpl implements ChineseSegmenter {

	/**
	 * this func will get chinese word from a list of stocks. You need analysis
	 * stocks' answer and get answer word. And implement this interface in the class
	 * : ChineseSegmenterImpl Example: 我今天特别开心 result : 我 今天 特别 开心
	 *
	 * @param stocks
	 *            stocks info
	 * @return chinese word
	 * @see ChineseSegmenterImpl
	 */
	@Override
	public List<String> getWordsFromInput(StockInfo[] stocks) {
		// TODO: write your code here
		List<String> list = new ArrayList<String>();

		for (int i = 0; i < stocks.length; i++) {
			// Result是每次循环单条ANSWER的的分词结果
			StopRecognition fitler = new StopRecognition();
			fitler.insertStopNatures("w"); // 过滤标点符号词性
			fitler.insertStopNatures("null");// 过滤null词性
			fitler.insertStopNatures("u");//过滤掉助词
			fitler.insertStopNatures("ude1");//过滤掉助词
			fitler.insertStopNatures("m");//过滤数字
			Result result = ToAnalysis.parse(stocks[i].getANSWER()).recognition(fitler);
			List<Term> terms = result.getTerms();
			// 遍历Result返回的String数组存入list中
			for (int j = 0; j < terms.size(); j++) {
				String temp = terms.get(j).getName();
				list.add(temp);
			}
		}
		return list;
	}
}
